package cn.bs.seckill.utils;

import org.apache.commons.codec.digest.DigestUtils;

/*本类用于md5加密*/
public class MD5Util {

    //盐值
    private static final String SALT = "1a2b3c4d";

    //md5加密方法
    public static String md5(String msg) {
        return DigestUtils.md5Hex(msg);
    }

    //第一次加密,把前端传入的数据加密
    public static String inputPassEpt(String inputPass) {
        //SALT.charAt(1):通过下标,选择(固定)盐值里面的第几个数
        String firstEncryption = "" + SALT.charAt(0) + SALT.charAt(2) + inputPass + SALT.charAt(5) + SALT.charAt(4);
        return md5(firstEncryption);
    }

    //随便加个密
    public static String toDBPassEpt(String firstEncryption) {
        String secondEncryption = "" + SALT.charAt(0) + SALT.charAt(2) + firstEncryption + SALT.charAt(5) + SALT.charAt(4);
        return md5(secondEncryption);
    }

    //把第一次加密后的密码再次加密
    //不要觉得绕,说白了这个方法就是整合上面的两个方法
    public static String inputPassToDBPass(String inputPass) {
        String firstEncryption = inputPassEpt(inputPass);
        String secondEncryption = toDBPassEpt(firstEncryption);
        return secondEncryption;
    }

    public static void main(String[] args) {
        System.out.println(inputPassEpt("123456"));
    }
}
